package br.com.java.dao.impl;

import java.io.Serializable;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import br.com.java.dao.AlunoDAO;
import br.com.java.entities.Aluno;

@Repository
public class AlunoDAOImpl extends GenericDAOImpl<Aluno, Long> implements Serializable, AlunoDAO {

	private static final long serialVersionUID = 2404360457246388280L;
	
	@SuppressWarnings("unchecked")
	public List<Aluno> retrieveByFilter(String matricula, String nome) {
		
		Session session = sessionFactory.openSession();
		Criteria criteria = session.createCriteria(Aluno.class);
		
		if (!matricula.contentEquals("")){
			criteria.add(Restrictions.like("matricula", matricula, MatchMode.START)); 
		}
		
		if (!nome.contentEquals("")){
			criteria.add(Restrictions.like("nome", nome, MatchMode.START)); 
		}
		
		List<Aluno> alunos = criteria.list();
		
		return alunos;
    }
	
}
